package com.solairen.myapplication;

import static com.solairen.myapplication.Pager.Util.UtilName.KEY_LOGIN_STATUS;
import static com.solairen.myapplication.Pager.Util.UtilName.KEY_NAME;
import static com.solairen.myapplication.Pager.Util.UtilName.KEY_PWD;
import static com.solairen.myapplication.Pager.Util.UtilName.PREFS_NAME;
import static com.solairen.myapplication.Pager.Util.UtilName.PREF_LOGGED_IN;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.solairen.myapplication.Pager.LoginPager.LoginNameActivity;
import com.solairen.myapplication.utils.UtilsKt;

/**
 * 设置页面
 */
public class SettingActivity extends AppCompatActivity {

    ImageView back;
    TextView delete;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.personnel_setting);
        initViews();
    }

    private void initViews(){
        back = findViewById(R.id.setting_iv_back);
        delete = findViewById(R.id.setting_exit);

        /********back**********/
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        /*******exit*********/
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                logout();
                // 跳转到登录页
                Intent intent = new Intent(SettingActivity.this, LoginNameActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
    }

    private void logout(){
        SharedPreferences sharedPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(KEY_LOGIN_STATUS, false);
        editor.apply();
    }
//    private void showDeleteDialog(){
//        AlertDialog.Builder builder = new AlertDialog.Builder(this)
//                .setTitle("delete data")
//                .setMessage("ensure?")
//                .setNegativeButton("no",null)
//                .setPositiveButton("yes", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//
//                        Toast.makeText(Setting.this,"delete success!",Toast.LENGTH_SHORT).show();
//                    }
//                });
//        builder.create().show();
//
//
//    }
}
